TOOLPATH = ../../tools/
INCPATH  = ../../tools/EMbote/

MAKE     = $(TOOLPATH)make.exe -r
NASK     = $(TOOLPATH)nask.exe
CC1      = $(TOOLPATH)cc1.exe -I$(INCPATH) -Os -Wall -quiet
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
OBJ2BIM  = $(TOOLPATH)obj2bim.exe
BIM2HRB  = $(TOOLPATH)bim2hrb.exe
RULEFILE = $(TOOLPATH)EMbote/EMbote.rul
EDIMG    = $(TOOLPATH)edimg.exe
IMGTOL   = $(TOOLPATH)imgtol.com
COPY     = copy
DEL      = del

default:
	$(MAKE) img

ipl.bin:ipl4.nas Makefile
	$(NASK) ipl4.nas ipl.bin ipl.lst

asmhead.bin:asmhead.nas Makefile
	$(NASK) asmhead.nas asmhead.bin asmhead.lst
bootpack.gas:bootpack1.c Makefile
	$(CC1) -o bootpack.gas bootpack1.c
bootpack.nas:bootpack.gas Makefile
	$(GAS2NASK) bootpack.gas bootpack.nas
bootpack.obj:bootpack.nas Makefile
	$(NASK) bootpack.nas bootpack.obj bootpack.lst
naskfunc.obj : naskfunc.nas Makefile
	$(NASK) naskfunc.nas naskfunc.obj naskfunc.lst
bootpack.bim : bootpack.obj naskfunc.obj Makefile
	$(OBJ2BIM) @$(RULEFILE) out:bootpack.bim stack:3136k map:bootpack.map \
		bootpack.obj naskfunc.obj
# 3MB+64KB=3136KB
bootpack.hrb : bootpack.bim Makefile
	$(BIM2HRB) bootpack.bim bootpack.hrb 0
	
EMOS.sys:asmhead.bin bootpack.hrb Makefile
	copy /B asmhead.bin+bootpack.hrb EMOS.sys
EMOS.img:ipl.bin EMOS.sys Makefile
	$(EDIMG)   imgin:../../tools/fdimg0at.tek \
		wbinimg src:ipl.bin len:512 from:0 to:0 \
		copy from:EMOS.sys to:@: \
		imgout:EMOS.img
	
asm:
	$(MAKE)  ipl.bin
	
img :
	$(MAKE)  EMOS.img

run:
	$(MAKE) img
	$(COPY) EMOS.img ..\..\tools\qemu\fdimage0.bin
	$(MAKE) -C ../../tools/qemu
	
clean:
	-del *.bin
	-del *.lst
	-del *.gas
	-del *.obj
	-$(DEL) bootpack.nas
	-$(DEL) bootpack.map
	-$(DEL) bootpack.bim
	-$(DEL) bootpack.hrb
	-del EMOS.sys